<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8" />
  <title>Vue监测数据改变的原理-数组</title>
  <!-- 引入Vue -->
  <script type="text/javascript" src="../js/vue.js"></script>
</head>

<body>
  <!-- 准备好一个容器-->
  <div id="root">
    <h1>学生信息</h1>
    <button @click="changeHobby">把烟戒了，去学习！</button>
    <h2>姓名：{{student.name}}</h2>
    <h2>爱好：</h2>
    <ul>
      <li v-for="(h,index) in student.hobby" :key="index">{{h}}</li>
    </ul>
  </div>
</body>

<script type="text/javascript">
  Vue.config.productionTip = false; // 阻止Vue在启动时生成生产提示。

  const vm = new Vue({
    el: "#root",
    data: {
      student: {
        name: "张三",
        hobby: ["抽烟", "喝酒", "烫头"]
      }
    },
    methods: {
      changeHobby() {
        this.$set(this.student.hobby, "0", "学习");
      }
    }
  });
</script>

</html>